package com.mytest.provider.es.serviceImpl;

import com.myrest.provider.poi.work.entities.user.ESUser;
import com.mytest.provider.es.mapper.ElasticRepository;
import com.mytest.provider.es.service.IElasticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
//import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;


/**
 * @Author: llq
 * @Date: 2020/4/8
 */
@Service("elasticService")
public class ElasticServiceImpl implements IElasticService {
    @Autowired
    private ElasticsearchTemplate elasticsearchTemplate;
    @Autowired
    private ElasticRepository elasticRepository;

    private Pageable pageable = PageRequest.of(0,10);

    @Override
    public void createIndex() {
        elasticsearchTemplate.createIndex(ESUser.class);
    }

    @Override
    public void deleteIndex(String index) {
        elasticsearchTemplate.deleteIndex(index);
    }

    @Override
    public void save(ESUser docBean) {
        elasticRepository.save(docBean);
    }

    @Override
    public void saveAll(List<ESUser> list) {
        elasticRepository.saveAll(list);
    }

    @Override
    public Iterator<ESUser> findAll() {
        return elasticRepository.findAll().iterator();
    }

//    @Override
//    public Page<ESUser> findByContent(String content) {
//        return elasticRepository.findByContent(content,pageable);
//    }

    /*@Override
    public Page<ESUser> findByFirstCode(String firstCode) {
        return elasticRepository.findByFirstCode(firstCode,pageable);
    }

    @Override
    public Page<ESUser> findBySecordCode(String secordCode) {
        return elasticRepository.findBySecordCode(secordCode,pageable);
    }*/

//    @Override
//    public Page<ESUser> query(String key) {
//        return elasticRepository.findByContent(key,pageable);
//    }
}
